<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Catalog extends CI_Controller {
    public function __construct() {
        parent::__construct();
        $this -> load -> model('catalog_model');
    }

    public function index($id='') {
        if($id!=''){
            echo $id;
        }
        $catalog = $this -> catalog_model -> get_song_names();
        $this -> load -> view('catalog', array('catalog' => json_encode($catalog)));
    }

    public function displaySong($song_id) {
        $song = $this -> catalog_model -> getSong($song_id);
        $this -> load -> view('song', $song);
    }

    public function saveSong() {
        $data = $this -> input -> post();
        if($data['song_id'] == ''){
            unset($data['song_id']);
        }
        $res = $this -> catalog_model -> saveSong($data);
        $this->index($res);
    }

    public function manageSong($song_id = '') {
        $song = array();
        if ($song_id != '') {
            $song = $this -> catalog_model -> getSong($song_id);
        }
        $this -> load -> view('songForm', $song);
    }

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
